<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>库存管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
 
    <!-- 库存列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">库存管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/stocks/list.action">
					<div class="form-group">
						<label for="bookName">图书名称</label> 
						<input type="text" class="form-control" id="bookName" 
						                   value="${bookName }" name="bookName" />
					</div>
					
					<button type="submit" class="btn btn-primary">查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newCustomerDialog" onclick="clearAuthor()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">库存信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>图书名称</th>
								<th>图书数量</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.stockid}</td>
									<td>${row.bookid}</td>
									<td>${row.quantity}</td>
									
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#customerEditDialog" onclick= "editCustomer(${row.stockid})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteCustomer(${row.stockid})">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath }/stocks/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	
	
	<!-- 库存列表查询部分  end-->
</div>
<!-- 创建库存模态框 -->
<div class="modal fade" id="newCustomerDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
		
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建库存信息</h4>
			</div>
			
			<div class="modal-body">
				<form class="form-horizontal" id="new_customer_form">
					<div class="form-group">
						<label for="new_customerName" class="col-sm-2 control-label">
						    图书名称
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_bookName" placeholder="图书名称" name="bookid" />
						</div>
					</div>
		
					<div class="form-group">
						<label for="new_address" class="col-sm-2 control-label">图书数量</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_bookQuantity" placeholder="图书数量" name="quantity" />
						</div>
					</div>
				</form>
			</div>
			
			
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createAuthor()">创建库存信息</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改库存模态框 -->
<div class="modal fade" id="customerEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
		
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改库存信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_customer_form">
					<input type="hidden" id="edit_stock_id" name="stockid"/>
					<div class="form-group">
						<label for="edit_customerName" class="col-sm-2 control-label">图书名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_bookName" placeholder="图书名称" name="bookid" />
						</div>
					</div>
										
					<div class="form-group">
						<label for="edit_address" class="col-sm-2 control-label">图书数量</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_bookQuantity" placeholder="图书数量" name="quantity" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateCustomer()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建客户窗口中的数据
	function clearAuthor() {
	    $("#new_bookName").val("");
	    $("#new_bookQuantity").val("")
	 
	}
	// 创建客户
	function createAuthor() {
	$.post("<%=basePath%>stock/create.action",
	$("#new_customer_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("库存创建成功！");
	            window.location.reload();
	        }else{
	            alert("库存创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的客户信息
	function editCustomer(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>stock/getStockById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#edit_stock_id").val(data.stockid);
	            $("#edit_bookName").val(data.bookid);
	            $("#edit_bookQuantity").val(data.quantity);
	            
	        }
	    });
	}
    // 执行修改作者操作
	function updateCustomer() {
		$.post("<%=basePath%>stock/update.action",$("#edit_customer_form").serialize(),function(data){
			if(data =="OK"){
				alert("库存信息更新成功！");
				window.location.reload();
			}else{
				alert("库存信息更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除作者
	function deleteCustomer(id) {
	    if(confirm('确实要删除该库存信息吗?')) {
	$.post("<%=basePath%>stock/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("库存信息删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除库存信息失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</body>
</html>